﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
//using JBSE.Models.FluentConfiguration;
using System.ComponentModel.DataAnnotations;
using Calendar.Models.Objects;
using JBSE.Models.FluentConfiguration;

namespace Calendar.Models
{
    public class CalendarContext : DbContext
    {

        public DbSet<MasterCode> MasterCodes { get; set; }
        public DbSet<Event> Events { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //Table per Type inheritance
            modelBuilder.Entity<MasterCode>().ToTable("MasterCodes");
            modelBuilder.Entity<Event>().ToTable("Events");
            
            modelBuilder.Configurations.Add(new MasterCodeConfiguration());
            modelBuilder.Configurations.Add(new EventConfiguration());

            //Cassade delete for MyListStorage and MyList
            modelBuilder.Entity<Event>()
                .HasRequired(m => m.MasterCode)
                .WithMany(s => s.Events)
                .HasForeignKey(m => m.MasterCodeId)
                .WillCascadeOnDelete(true);
        }

    }
}